------------------ fgui require start ------------------
------------------  fgui require end  ------------------
local Listdetails1Skin = Class("Listdetails1Skin");

function Listdetails1Skin:ctor(com)
    ------------------ fgui事件绑定start ------------------
    self:bindChild(com);
    self.position.onChanged:Add(self.onChange_position, self);
    self.state.onChanged:Add(self.onChange_state, self);
    self.btn_head.onClick:Add(self.onTouch_btn_head, self);
    self.btn_active.onClick:Add(self.onTouch_Btn_active, self);
    self.btn_FriendCompeteBattle.onClick:Add(self.onTouch_Friend_Compete_Battle, self);
    self:init();
    ------------------  fgui事件绑定end  ------------------
end

function Listdetails1Skin:bindChild(com)
    ------------------ fgui变量绑定start ------------------
    self.fguiObj = com;
    self.position = com:GetController("position");
    self.state = com:GetController("state");
    self.isMe = com:GetController("isMe");
    self.btn_head = com:GetChild("btn_head");
    self.btn_active = com:GetChild("Btn_active");
    self.btn_FriendCompeteBattle = com:GetChild("btn_FriendCompeteBattle")
    self.text_lvName = com:GetChild("Text_lvName");
    self.text_lv = com:GetChild("Text_lv");
    self.text_name = com:GetChild("Text_name");
    self.text_power = com:GetChild("Text_power");
    self.img_power = com:GetChild("Img_Combateffectiveness");
    self.text_deputyhead = com:GetChild("Text_deputyhead");
    self.text_president = com:GetChild("Text_president");
    self.text_online = com:GetChild("Text_online");
    ------------------  fgui变量绑定end  ------------------
    self.frame = self.btn_head:GetChild("frame");
    self.icon = self.btn_head:GetChild("head"):GetChild("HeadIcon");
end

function Listdetails1Skin:init()
    self.data = nil;
    self._touchBtnActiveCallback = nil;
    self.text_president.text = getLanguage("GuildInvestment_1053");
    self.text_deputyhead.text = getLanguage("GuildInvestment_1054");
end

function Listdetails1Skin:OnDestroy()
    ------------------ fgui事件移除start ------------------
    self:beforeDestroy();
    self.position.onChanged:Clear();
    self.state.onChanged:Clear();
    self.btn_head.onClick:Clear();
    self.btn_active.onClick:Clear();
    ------------------  fgui事件移除end  ------------------
end

function Listdetails1Skin:onChange_position(event)
end

function Listdetails1Skin:onChange_state(event)
end

function Listdetails1Skin:onTouch_btn_head(obj)
    if  tostring(logicMgr.HeroManager.GetRoleInfo().playerId) == tostring(self:getPlayerId()) then
        -- showUI(PanelNames.UIHeadInfo);
        UISysTips.AddMsg(getLanguage("GuildInvestment_1200"));
    else
        roleInfoHandler.sendreqOtherRoleInfo(self:getPlayerId());
    end
end

function Listdetails1Skin:onTouch_Btn_active(obj)
    EventContext.StopPropagation(obj);
    if self._touchBtnActiveCallback then
        self._touchBtnActiveCallback(self);
    end
end
--切磋
function Listdetails1Skin:onTouch_Friend_Compete_Battle(obj)
    friendHandler.ReqFriendCompeteInfo(self.data.showInfo.playerId)
end

------------------  ↑ fgui事件句柄 ↑  ------------------

function Listdetails1Skin:getPlayerId()
    return self.data.showInfo.playerId;
end

function Listdetails1Skin:onRender(data,isTeammate)
    self.data = data;
    self.text_name.text = data.showInfo.name;
    self.text_power.text = getNumString(toNumber(tostring(data.showInfo.maxPower)));
    if isTeammate then
        self.text_power.visible = true
        self.img_power.visible = true
    else
        self.text_power.visible = false
        self.img_power.visible = false
    end
    self.btn_active.text = tostring(data.livenessWeek);
    self.text_lv.text = data.showInfo.level;
    self.frame.url = "ui://ICONAtlas/" .. data.showInfo.picFrame;
    self.icon.url = logicMgr.SkinManager.GetHeroIconBySkinId(data.showInfo.pic) --"ui://ICONAtlas/" .. dataTable.getRow("t_hero", data.showInfo.pic)["f_HeroIcon"]
    local selIdx = 2;
    if data.jobId == logicMgr.GuildManager.JOB_VICECHAIRMAN_ID then
        selIdx = 1;
    elseif data.jobId == logicMgr.GuildManager.JOB_CHAIRMAN_ID then
        selIdx = 0;
    end
    self.position.selectedIndex = selIdx;
    self.state.selectedIndex = 0;
    if data.offlineTime then
        local offlineTime = tonumber(tostring(data.offlineTime));
        if offlineTime > 0 then
            self.text_online.text = getLanguage("GuildInvestment_1076") .. getTimeStrType2(offlineTime);
            self.state.selectedIndex = 1;
        else
            self.text_online.text = getLanguage("GuildInvestment_1077");
        end
    else
        self.text_online.text = getLanguage("GuildInvestment_1077");
    end
    if self.isMe then
        if tostring(self:getPlayerId()) == logicMgr.HeroManager.GetRoleId() then
            self.isMe.selectedIndex = 1;
        else
            self.isMe.selectedIndex = 0;
        end
    end
end

function Listdetails1Skin:setTouchBtnActiveCallback(callback)
    self._touchBtnActiveCallback = callback;
end

function Listdetails1Skin:beforeDestroy()
    self._touchBtnActiveCallback = nil;
end

return Listdetails1Skin;
